package cn.hanyx.coder.design.pattern.creational.factory.simple.demo04;

import cn.hanyx.coder.design.pattern.creational.factory.simple.demo01.*;

import java.util.HashMap;
import java.util.Map;

/**
 * RuleConfigParserFactory
 *
 * @author hanyx
 * @date 2020/07/14
 */
public class RuleConfigParserFactory {
    private static final Map<String, IRuleConfigParser> cachedParse = new HashMap<>();

    static {
        cachedParse.put("json", new JsonRuleConfigParser());
        cachedParse.put("xml", new XmlRuleConfigParser());
        cachedParse.put("yaml", new YamlRuleConfigParser());
        cachedParse.put("properties", new PropertiesRuleConfigParser());
    }

    public static IRuleConfigParser createParse(String ruleConfigFileExtension) throws Exception {
        return cachedParse.get(ruleConfigFileExtension);
    }
}
